//
//  MainTabbar.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/10/18.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "MainTabbar.h"

@implementation MainTabbar

-(UIButton *)plusBtn{
    
#pragma mark :注意,懒加载一定要规范写,前面加if判断,否则可能会重复添加,造成叠加,影响使用
    if (!_plusBtn){
        _plusBtn = [[UIButton alloc]init];
        
        [_plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [_plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        [_plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_plusBtn setBackgroundImage:[UIImage imageNamed: @"tabbar_compose_button_highlighted"] forState:UIControlStateSelected];
        [self addSubview:_plusBtn];
    }
    
    return _plusBtn;
    
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    int index = 0;
    CGFloat w = self.bounds.size.width / 5;
    CGFloat h = self.bounds.size.height;
    CGRect rect = CGRectMake(0, 0, w, h);
    
    for (id subViews in self.subviews) {
        
        Class class = NSClassFromString(@"UITabBarButton");
        
        if ([subViews isKindOfClass:class]) {
//            NSLog(@"----%@------", subViews);
            if (index == 2) {
                index = 3;
            }
            [subViews setFrame:CGRectOffset(rect, index * w, 0)];
            index++;
        }
        }
    
  self.plusBtn.frame = CGRectMake(2 * w, 0, w, h);
}



@end
